﻿@model NewsView




<div>
    <div class="layui-container" style="margin-top:50px;margin-bottom:150px">
        <form class="layui-form" id="addForm" onsubmit="return false" style="margin-top:50px">
            @* 类别 *@
            <div class="layui-form-item">
                <label class="layui-form-label">类别分类</label>
                <div class="layui-input-block">
                    <select asp-for="NewsTypeId" asp-items="@ViewBag.TypeName"></select>
                </div>
            </div>
            @*标题*@
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" asp-for="Title" class="layui-input" />
                    <span asp-validation-for="Title" style="color: #F56C6C"></span>

                </div>
            </div>
            @*创建日期*@
            @*<div class="layui-form-item">
                    <label class="layui-form-label">创建日期</label>
                    <div class="layui-input-block">
                        <input type="text" id="Time" class="layui-input" placeholder="请输入日期" style="margin-top"/ >
                    </div>
                </div>*@
            @* 内容 *@
            <div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <input type="text" asp-for="Cont" class="layui-input" />
                    @*<textarea lay-filter="content" asp-for="Cont" ></textarea>*@
                    <span asp-validation-for="Cont" style="color: #F56C6C"></span>
                </div>
            </div>
            @*是否发布*@
            <div class="layui-form-item">
                <label class="layui-form-label">是否发布</label>
                <div class="layui-input-block">
                    <select asp-for="HomeFlag">
                        <option value=""></option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                    <span asp-validation-for="HomeFlag" style="color: #F56C6C"></span>
                </div>
            </div>

            @*提交和重置按钮*@
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="subAdd"> 立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>



@section Scripts{
    <script>
        layui.use(['form'], function () {
            var form = layui.form;
            var layedit = layui.layedit;
            var upload = layui.upload;
            var $ = layui.$;
            var layer = layui.layer;

            //var index = layedit.build('content'); //建立编辑器
            //form.verify({
            //    content: function () {
            //        layedit.sync(index);
            //    }
            //})
            //监听提交
            form.on('submit(subAdd)', function (data) {
                $.post("/Admin/News/Add", data.field, function (re) {
                    if (re.success) {
                        //发异步，把数据提交给
                        layer.alert(re.msg, { icon: 6 }, function () {
                            parent.layui.$("#subAdd").click();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                            //layer.msg(res.msg);
                            //关闭当前窗口，并且刷新列表
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(re.msg);
                    }

                }, "json");

                return false;
            });

        });
    </script>

}
